package com.cci.kangdao.controller;

import com.cci.kangdao.service.SceneTechnicalConfirmationService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class SceneTechnicalConfirmationController {


	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private SceneTechnicalConfirmationService sceneTechnicalConfirmationService;


	//技师提交现场技术确认信息接口    故障码症状是数组
	@RequestMapping( "/submitSceneTechnicalConfirmationMsg.aspx")
	public ModelAndView submitSceneTechnicalConfirmationMsg(HttpServletRequest request,
											 HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			map = ParameterTool.getRequestBody(request);
			map.put("request", request);
			map.put("response", response);
			return sceneTechnicalConfirmationService.submitSceneTechnicalConfirmationMsg(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//获取现场技术确认信息
	@RequestMapping("/getSceneTechnicalConfirmationMsg.aspx")
	public ModelAndView getSceneTechnicalConfirmationMsg(HttpServletRequest request,
															HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return sceneTechnicalConfirmationService.getSceneTechnicalConfirmationMsg(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


    //新增故障码症状接口
    @RequestMapping("/insertFaultCodeSymptomList.aspx")
    public ModelAndView insertFaultCodeSymptomList(HttpServletRequest request,
                                                         HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			map = ParameterTool.getRequestBody(request);
			map.put("request", request);
			map.put("response", response);
            return sceneTechnicalConfirmationService.insertFaultCodeSymptomList(map);
        }catch(Exception ex){
            log.error(ex.getMessage(),ex);

            String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }
}
